package com.a.a;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;

class g extends CharsetEncoder {
    static boolean a;
    private final e b;
    private final a c;
    private final byte d;
    private final byte e;
    private final boolean f;
    private boolean g;
    private int h;
    private int i;

    static {
        String property = System.getProperty("java.specification.version");
        String property2 = System.getProperty("java.vm.vendor");
        boolean z = "1.4".equals(property) || "1.5".equals(property);
        a = z;
        a &= "Sun Microsystems Inc.".equals(property2);
    }

    g(e eVar, a aVar, boolean z) {
        super(eVar, 1.5f, 5.0f);
        this.b = eVar;
        this.c = aVar;
        this.f = z;
        this.d = eVar.a();
        this.e = eVar.b();
    }

    private void a(char c, ByteBuffer byteBuffer) {
        if (!this.g) {
            byteBuffer.put(this.d);
        }
        this.g = true;
        this.h += 16;
        while (this.h >= 6) {
            this.h -= 6;
            this.i += c >> this.h;
            this.i &= 63;
            byteBuffer.put(this.c.a(this.i));
            this.i = 0;
        }
        this.i = (c << (6 - this.h)) & 63;
    }

    private void a(ByteBuffer byteBuffer, char c) {
        if (this.g) {
            if (this.h != 0) {
                byteBuffer.put(this.c.a(this.i));
            }
            if (this.c.a(c) || c == this.e || this.f) {
                byteBuffer.put(this.e);
            }
            this.g = false;
            this.i = 0;
            this.h = 0;
        }
    }

    protected CoderResult encodeLoop(CharBuffer charBuffer, ByteBuffer byteBuffer) {
        while (charBuffer.hasRemaining()) {
            if (byteBuffer.remaining() < 4) {
                return CoderResult.OVERFLOW;
            }
            char c = charBuffer.get();
            if (this.b.a(c)) {
                a(byteBuffer, c);
                byteBuffer.put((byte) c);
            } else if (this.g || c != this.d) {
                a(c, byteBuffer);
            } else {
                byteBuffer.put(this.d);
                byteBuffer.put(this.e);
            }
        }
        return (this.g && a && ((float) byteBuffer.limit()) != 5.0f * ((float) charBuffer.limit())) ? CoderResult.OVERFLOW : CoderResult.UNDERFLOW;
    }

    protected CoderResult implFlush(ByteBuffer byteBuffer) {
        if (this.g) {
            if (byteBuffer.remaining() < 2) {
                return CoderResult.OVERFLOW;
            }
            if (this.h != 0) {
                byteBuffer.put(this.c.a(this.i));
            }
            byteBuffer.put(this.e);
        }
        return CoderResult.UNDERFLOW;
    }

    protected void implReset() {
        this.g = false;
        this.i = 0;
        this.h = 0;
    }
}
